package Solution_2;

import java.util.Scanner;

/**
 * 编程获取两个指定字符串中的最大相同子串。
 *
 *  如： s1="asdafghjka", s2="aaasdfg" 他们的最大子串为"asd"
 *
 *  提示： 将短的那个串进行长度依次递减的子串与较长的串比较。
 */

//用递归
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s1 = in.next(),s2=in.next();
        if(s1.length() < s2.length()){
            String t = s1;
            s1 = s2;
            s2 = t;
        }
        //s1="asdafghjka";
       // s2="aaasdfg";
        System.out.println(find(s1,s2,""));
    }
    public static String find(String s1,String s2,String r){
        String result = "";
        if(s2.length() == 0) return  result;

        //if (s1.contains( s2)) result = s2;
        if(s1.contains(result = s2) || s1.contains(result = s2.substring(1)) || s1.contains(result = s2.substring(0,s2.length()-1)));
        else result = "";

            String a = find(s1,s2.substring(1),result) ;
            result = a.length() < result.length() ? result : a;

            a = find(s1,s2.substring(0,s2.length()-1),result);
            result = a.length() < result.length() ? result : a;

        return result;
    }
}
